<?php

class TopMenu
{
    public static function Generate( $pageId )
    {
        $tmpl = Core::CreateTemplateEngine( PATH_TEMPLATES."include/menu/top/" );

        $tmpl->define("active",   "active.tpl");
        $tmpl->define("selected", "selected.tpl");
        $tmpl->set('menu', '');

        $pageTree = Pages::GetRootPage();
        foreach ( $pageTree->children as $id )
        {
            $pageInfo = Pages::GetPageInfo($id);
            if ( $pageInfo->top )
            {
                $tmpl->set('LINK', UrlHelper::GetAbsolutePath($pageInfo->path));
                $tmpl->set('TEXT', $pageInfo->name);
                $tmpl->parse("menu", ($id == $pageId) ? ".selected" : ".active");
            }
        }

        return $tmpl->getGenerated('menu');
    }
}

?>
